package impl;

import java.sql.ResultSet;

import business.basic.BaseDAO;
import business.basic.BaseDaoImpl;
import DAO.UserDAO;
import Model.TUser;

public class TUserimpl implements UserDAO {

	BaseDAO bdao =new BaseDaoImpl();
//	public void init()
//	{
//		bdao = new BaseDaoImpl();
//	}
	@Override
	public Object addUser(TUser tu) {
		String sql="insert into T_User(id, phone, pwd) Values (?,?,?)";
		Object[] para = {tu.getId(),tu.getPhone(),tu.getPwd()};		
		return bdao.insert(sql, para);

	}
	@Override
	public boolean addUserall(TUser tu) {
		String sqlString="insert into T_User(id, name, ageaed, birthday, phone, usertype, username, pwd, e-mail, photo,IDnum) Values (?,?,?,?,?,?,?,?)";
		Object[] para = {tu.getName(),tu.getAgeaed(),tu.getBirthday(),tu.getPhone(),tu.getUsertype(),
				tu.getPwd(),tu.getEmail(),tu.getPhoto(),tu.getIDnum()};
		if(bdao.insert(sqlString, para)==0){
			return true;  
			
		}else {
			 return false;
		}
	}

	@Override
	public boolean deleteUser(TUser tu) {
		String sqlString="delete from T_User where id = ?";
		Object[] para = {tu.getId()};
		if((Integer)bdao.delete(sqlString, para)>0){
			return true;
		}else {
			return false;
		}
	}

	@Override
	public boolean updateUser(TUser tu) {
		String sqlString="UPDATE T_User SET name=?, ageaed=?, birthday=?, phone=?, usertype=?, username=?, pwd=?, e-mail=?, photo=? WHERE id=?";
		Object[] para = {tu.getName(),tu.getAgeaed(),tu.getBirthday(),tu.getPhone(),tu.getUsertype(),
				tu.getPwd(),tu.getEmail(),tu.getPhoto(),tu.getId()};
		if((Integer)bdao.update(sqlString, para)>0){
			return true;
		}else {
			return false;
		}
	}

	@Override
	public TUser selectUser(int id,String pwd) {
		String sql = "select * from T_User where id = ? and pwd=?";
		Object[] para ={id,pwd};
		ResultSet rs = bdao.select(sql,para);
		TUser tc=new TUser(rs);		
		return tc;
	}
	@Override
	public ResultSet logintUser(int id, String pwd) {
		String sql = "select * from T_User where id = ? and pwd=?";
		Object[] para ={id,pwd};
		ResultSet rs = bdao.select(sql,para);
			
		return rs;
	}


}
